// filename: MainScene.cpp
// author: enic
// date: 2016-03-08

#pragma once

#include "MainScene.h"
#include "VisibleRect.h"
#include "../XLib/XBase/string_utf_convert.h"
#include "utility.h"
#include "GameScene.h"

#include <cocos2d/cocos/ui/CocosGUI.h>

namespace EZFY
{
	MainScene::MainScene()
	{

	}

	MainScene::~MainScene()
	{

	}

	bool MainScene::init()
	{
		bool bRet = TSuperClass::init();
		CCASSERT(bRet, "init failed!");

		// load plist
		std::vector<std::wstring> vecGamePlistFiles =
		{
			_T("EZFY/Game/B3.plist"),
			_T("EZFY/Game/G1.plist"),
			_T("EZFY/Game/G10.plist"),
			_T("EZFY/Game/G11.plist"),
			_T("EZFY/Game/G12.plist"),
			_T("EZFY/Game/G13.plist"),
			_T("EZFY/Game/G14.plist"),
			_T("EZFY/Game/G15.plist"),
			_T("EZFY/Game/G16.plist"),
			_T("EZFY/Game/G17.plist"),
			_T("EZFY/Game/G18.plist"),
			_T("EZFY/Game/G19.plist"),
			_T("EZFY/Game/G2.plist"),
			_T("EZFY/Game/G20.plist"),
			_T("EZFY/Game/G21.plist"),
			_T("EZFY/Game/G22.plist"),
			_T("EZFY/Game/G23.plist"),
			_T("EZFY/Game/G24.plist"),
			_T("EZFY/Game/G25.plist"),
			_T("EZFY/Game/G26.plist"),
			_T("EZFY/Game/G27.plist"),
			_T("EZFY/Game/G28.plist"),
			_T("EZFY/Game/G29.plist"),
			_T("EZFY/Game/G3.plist"),
			_T("EZFY/Game/G30.plist"),
			_T("EZFY/Game/G31.plist"),
			_T("EZFY/Game/G32.plist"),
			_T("EZFY/Game/G4.plist"),
			_T("EZFY/Game/G5.plist"),
			_T("EZFY/Game/G6.plist"),
			_T("EZFY/Game/G7.plist"),
			_T("EZFY/Game/G8.plist"),
			_T("EZFY/Game/G9.plist"),
			_T("EZFY/Game/Game1.plist"),
			_T("EZFY/Game/Gtubiao.plist"),
			_T("EZFY/Game/putong.plist"),
			_T("EZFY/Game/T1.plist"),
			_T("EZFY/Game/T10.plist"),
			_T("EZFY/Game/T2.plist"),
			_T("EZFY/Game/T3.plist"),
			_T("EZFY/Game/T4.plist"),
			_T("EZFY/Game/T5.plist"),
			_T("EZFY/Game/T6.plist"),
			_T("EZFY/Game/T7.plist"),
			_T("EZFY/Game/T8.plist"),
			_T("EZFY/Game/T9.plist"),
			_T("EZFY/Game/Theme1.plist"),
			_T("EZFY/Game/Theme2.plist"),
			_T("EZFY/Game/Theme3.plist"),
			_T("EZFY/Game/Theme4.plist"),

			_T("EZFY/Main/Main.plist"),
		};

		utility::AddPlistToSpriteFrameCache(vecGamePlistFiles);

		//cocos2d::visib
		cocos2d::FileUtils::getInstance()->addSearchPath("EZFY");
		auto pSprBK = cocos2d::Sprite::create("Main/Ma_background.png");
		pSprBK->setPosition(VisibleRect::center());
		this->addChild(pSprBK);

		// logup
		cocos2d::Sprite* pSprLogoup1 = cocos2d::Sprite::createWithSpriteFrameName(XLocalT8("EZFY/Main/Ma_logoUp.png"));
		pSprLogoup1->setPosition(VisibleRect::center());
		this->addChild(pSprLogoup1);

		cocos2d::Sprite* pSprLogoup2 = cocos2d::Sprite::createWithSpriteFrameName(XLocalT8("EZFY/Main/Ma_logoUp2.png"));
		pSprLogoup2->setPosition(VisibleRect::center());
		this->addChild(pSprLogoup2);

		// logo
		//cocos2d::Sprite* pSrpLogo = cocos2d::Sprite::createWithSpriteFrameName(XLocalT8("EZFY/Main/Ma_logo.png"));
		//pSrpLogo->setPosition(ccpAdd(VisibleRect::top(), cocos2d::Point(0, 70 * 0.8)));
		//pSrpLogo->setPosition(VisibleRect::center());
		//this->addChild(pSrpLogo, 1);

		// play btn
		//cocos2d::ui::Button* pBtnPlay = cocos2d::ui::Button::create(XLocalT8("EZFY/Main/Ma_play.png"));
		cocos2d::ui::Button* pBtnPlay = cocos2d::ui::Button::create(
			XLocalT8("EZFY/Main/Ma_logo.png"),
			XLocalT8("EZFY/Main/Ma_logo.png"),
			XLocalT8("EZFY/Main/Ma_logo.png"),
			cocos2d::ui::Widget::TextureResType::PLIST);
		//pBtnPlay->setAnchorPoint(cocos2d::Point(0, 0));
		pBtnPlay->setPosition(VisibleRect::center());
		this->addChild(pBtnPlay);
		pBtnPlay->setPressedActionEnabled(true);
		pBtnPlay->addClickEventListener(CC_CALLBACK_1(MainScene::OnClickPay, this));

		return true;
	}

	void MainScene::OnClickPay(Ref* sender)
	{
		//::exit(0);
		GameScene* pNode = GameScene::create();
		this->addChild(pNode);
	}

};  //~ end of EZFY